<template>
    <div class='my'>
        <h1>个人中心</h1>
        欢迎：{{username}}
        <p><button @click="remove">退出登录</button></p>
    </div>
</template>

<script>
export default {
    data() {
        return {
            username:localStorage.getItem("user")
        };
    },
    mounted() {},
    methods: {
        remove(){
            localStorage.removeItem("user")
            this.$router.push({path:"/login"})
        }
    },
    beforeRouteEnter (to, from, next) {
        if(localStorage.getItem("user")){
            next()
        }else{
            next("/login")
        }
    }
};
</script>

<style lang='scss'>

</style>
